import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
from utils import apply_scaling
if "jms_style_sheet" in plt.style.available:
plt.style.use("jms_style_sheet")
df = pd.read_csv("diabetes.csv")
df.head()
| Pregnancies | Glucose | BloodPressure | SkinThickness | Insulin | BMI | DiabetesPedigreeFunction | Age | Outcome | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 6 | 148 | 72 | 35 | 0 | 33.6 | 0.627 | 50 | 1 |
| 1 | 1 | 85 | 66 | 29 | 0 | 26.6 | 0.351 | 31 | 0 |
| 2 | 8 | 183 | 64 | 0 | 0 | 23.3 | 0.672 | 32 | 1 |
| 3 | 1 | 89 | 66 | 23 | 94 | 28.1 | 0.167 | 21 | 0 |
| 4 | 0 | 137 | 40 | 35 | 168 | 43.1 | 2.288 | 33 | 1 |
target = "Outcome"
df.describe()
| Pregnancies | Glucose | BloodPressure | SkinThickness | Insulin | BMI | DiabetesPedigreeFunction | Age | Outcome | |
|---|---|---|---|---|---|---|---|---|---|
| count | 768.000000 | 768.000000 | 768.000000 | 768.000000 | 768.000000 | 768.000000 | 768.000000 | 768.000000 | 768.000000 |
| mean | 3.845052 | 120.894531 | 69.105469 | 20.536458 | 79.799479 | 31.992578 | 0.471876 | 33.240885 | 0.348958 |
| std | 3.369578 | 31.972618 | 19.355807 | 15.952218 | 115.244002 | 7.884160 | 0.331329 | 11.760232 | 0.476951 |
| min | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.078000 | 21.000000 | 0.000000 |
| 25% | 1.000000 | 99.000000 | 62.000000 | 0.000000 | 0.000000 | 27.300000 | 0.243750 | 24.000000 | 0.000000 |
| 50% | 3.000000 | 117.000000 | 72.000000 | 23.000000 | 30.500000 | 32.000000 | 0.372500 | 29.000000 | 0.000000 |
| 75% | 6.000000 | 140.250000 | 80.000000 | 32.000000 | 127.250000 | 36.600000 | 0.626250 | 41.000000 | 1.000000 |
| max | 17.000000 | 199.000000 | 122.000000 | 99.000000 | 846.000000 | 67.100000 | 2.420000 | 81.000000 | 1.000000 |
tmp = (df[target]
.value_counts()
.to_frame()
.reset_index()
.rename(columns={"index": "Outcome_name", "Outcome": "Outcome_count"})
)
fig = px.bar(data_frame=tmp,
x="Outcome_name",
y="Outcome_count",
color="Outcome_name")
fig.show()
# _ = plt.figure(figsize=(20, 4))
fig = px.imshow(df.T)
fig.show()
# _ = plt.figure(figsize=(20, 4))
fig = px.imshow(df
.pipe(apply_scaling)
.T)
fig.show()
# _ = plt.figure(figsize=(7, 4))
fig = px.imshow(df.corr())
fig.show()
# _ = plt.figure(figsize=(20, 4))
fig = px.strip(df
.pipe(apply_scaling, "MinMax")
.melt(id_vars = target),
x = "variable",
y = "value",
color = target,)
fig.show()
# _ = plt.figure(figsize=(20, 4))
fig = px.violin(df
.pipe(apply_scaling, "MinMax")
.melt(id_vars = target),
x = "variable",
y = "value",
color = target,
)
fig.show()